package com.bestcem.xm.user.dao.impl;

import com.bestcem.xm.user.dao.OrganizationCustomSettingDao;
import com.bestcem.xm.user.dao.mapper.OrganizationCustomSettingMapper;
import com.bestcem.xm.user.entity.mysql.OrganizationCustomSetting;
import com.bestcem.xm.user.entity.pojo.OrganizationCustomSettingDO;
import com.bestcem.xm.user.util.business.DataBaseUtil;
import com.bestcem.xm.user.util.convert.OrganizationCustomSettingConvert;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * 租户自定义配置信息服务
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/5/10 10:51
 */
@Repository
public class OrganizationCustomSettingDaoImpl implements OrganizationCustomSettingDao {

    @Resource
    private OrganizationCustomSettingMapper organizationCustomSettingMapper;

    @Resource
    private OrganizationCustomSettingConvert organizationCustomSettingConvert;

    @Override
    public String insert(OrganizationCustomSettingDO organizationCustomSettingDO) {
        OrganizationCustomSetting organizationCustomSetting = organizationCustomSettingConvert.do2Mysql(organizationCustomSettingDO);
        organizationCustomSetting.setId(DataBaseUtil.generateId());
        DataBaseUtil.setCreateAndUpdateTime(organizationCustomSetting);
        organizationCustomSettingMapper.insert(organizationCustomSetting);
        return organizationCustomSetting.getId();
    }

    @Override
    public String insertSelective(OrganizationCustomSettingDO organizationCustomSettingDO) {
        OrganizationCustomSetting organizationCustomSetting = organizationCustomSettingConvert.do2Mysql(organizationCustomSettingDO);
        organizationCustomSetting.setId(DataBaseUtil.generateId());
        DataBaseUtil.setCreateAndUpdateTime(organizationCustomSetting);
        organizationCustomSettingMapper.insertSelective(organizationCustomSetting);
        return organizationCustomSetting.getId();
    }

    @Override
    public OrganizationCustomSettingDO selectById(String id) {
        return organizationCustomSettingConvert.mysql2Do(organizationCustomSettingMapper.selectByPrimaryKey(id));
    }

    @Override
    public List<OrganizationCustomSettingDO> selectBySelective(OrganizationCustomSettingDO organizationCustomSettingDO) {
        OrganizationCustomSetting organizationCustomSetting = organizationCustomSettingConvert.do2Mysql(organizationCustomSettingDO);
        List<OrganizationCustomSetting> organizationCustomSettings = organizationCustomSettingMapper.selectBySelective(organizationCustomSetting);
        return organizationCustomSettingConvert.mysqls2Dos(organizationCustomSettings);
    }

    @Override
    public Integer updateSelectiveById(OrganizationCustomSettingDO organizationCustomSettingDO) {
        OrganizationCustomSetting organizationCustomSetting = organizationCustomSettingConvert.do2Mysql(organizationCustomSettingDO);
        DataBaseUtil.setUpdateTime(organizationCustomSetting);
        return organizationCustomSettingMapper.updateByPrimaryKeySelective(organizationCustomSetting);
    }

    @Override
    public Integer deleteById(String id) {
        return organizationCustomSettingMapper.deleteByPrimaryKey(id);
    }

}
